<?php

$info=json_decode($this->input->raw_input_stream,true);				
if($this->goods_model->getbytbid($info["id"],$shop["id"])) die("exist");
$product=array(
    "catid"=>$shop["id"],
    "tbid"=>$info["id"],
    "name"=>$info["name"],
    "thumb"=>serialize($info["img"]),
    "source"=>"Etsy",
    "source_url"=>$info["url"],
    "price"=>$info["price"],
    "sales"=>$info["sales"],
    "desc"=>preg_replace("/<a[^>]*href=[^>]*>|<\/[^a]*a[^>]*>/i","",$info["desc"]),
);
$prop=array();
if($info["extra"]){
    foreach($info["extra"] as $k=>$option)
    {
        if(isset($option["price"]) && $option["price"])
        {
            $price = $option["price"];
        }
        else
        {
            $price = [];
        }
        $prop["vv"][]=array("name"=>$option["name"],"value"=>$option["value"],"price"=>$price);
    }   
}

$product["option"]=serialize($prop);

if($this->goods_model->create($product)){
    die("ok");
}else{
    die("error");
}
